<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<title>AmpleHarvest: cFacets.php Source File</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">AmpleHarvest
   &#160;<span id="projectnumber">0.0.1</span>
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.5.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('c_facets_8php.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">cFacets.php</div>  </div>
</div>
<div class="contents">
<a href="c_facets_8php.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 &lt;?php
<a name="l00002"></a><a class="code" href="namespaceampleharvest_1_1code_1_1search.html">00002</a>         <span class="keyword">namespace </span>ampleharvest\code\search;
<a name="l00003"></a>00003         use\ampleharvest\code;
<a name="l00004"></a>00004 
<a name="l00005"></a>00005         require_once dirname(dirname(dirname(__FILE__))) . <span class="stringliteral">&#39;/config/cConfig.php&#39;</span>;
<a name="l00006"></a>00006 
<a name="l00007"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html">00007</a>         <span class="keyword">class </span><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html">cFacets</a>
<a name="l00008"></a>00008         {
<a name="l00009"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#afe107c5cffbd23fb30b4a0f539bef754">00009</a>                 <span class="keyword">const</span> C_INT_SOLR_TYPE_REAPER = 0;
<a name="l00010"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#a7c3371dee8f62cc0cc1ef489c2c681f2">00010</a>                 <span class="keyword">const</span> C_INT_SOLR_TYPE_GROUNDEFFECT = 1;
<a name="l00011"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#a28e0eb82cf1a70c840417a75371b2900">00011</a>                 <span class="keyword">const</span> C_INT_SOLR_TYPE_WIKI = 2;
<a name="l00012"></a>00012 
<a name="l00013"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#a985530f019d20de9c25e685f537795ca">00013</a>                 <span class="keyword">private</span> <a class="code" href="classc_facets.html#a985530f019d20de9c25e685f537795ca">$m_obj_Solr</a> = null;
<a name="l00014"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#a58f8e693c688cba33ca43151c88e8bc5">00014</a>                 <span class="keyword">private</span> <a class="code" href="classc_facets.html#a58f8e693c688cba33ca43151c88e8bc5">$m_str_Prefix</a> = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00015"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#a797ddc2beeeb6f3a7ed0efdf973dcb88">00015</a>                 <span class="keyword">private</span> <a class="code" href="classc_facets.html#a797ddc2beeeb6f3a7ed0efdf973dcb88">$m_str_BaseQuery</a> = <span class="stringliteral">&quot;*:*&quot;</span>;
<a name="l00016"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#a6d5800afb69350215c2a88890187526d">00016</a>                 <span class="keyword">private</span> <a class="code" href="classc_facets.html#a6d5800afb69350215c2a88890187526d">$m_str_Facet</a> = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00017"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#abe154d4e6c6dfbc21d055c77a7bffaf1">00017</a>                 <span class="keyword">private</span> $m_int_SolrType = <span class="stringliteral">&quot;&quot;</span>;
<a name="l00018"></a>00018 
<a name="l00019"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#af7487923f3ce6ec311b2ab2a979d3a00">00019</a>                 <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="classc_facets.html#af7487923f3ce6ec311b2ab2a979d3a00">set_Prefix</a>($str_Prefix)
<a name="l00020"></a>00020                 {
<a name="l00021"></a>00021                         $this-&gt;m_str_Prefix = $str_Prefix;
<a name="l00022"></a>00022                 }
<a name="l00023"></a>00023 
<a name="l00024"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#ad049e138be222ce60d59cb288619be8c">00024</a>                 <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="classc_facets.html#ad049e138be222ce60d59cb288619be8c">set_Facet</a>($str_Facet)
<a name="l00025"></a>00025                 {
<a name="l00026"></a>00026                         $this-&gt;m_str_Facet = $str_Facet;
<a name="l00027"></a>00027                 }
<a name="l00028"></a>00028 
<a name="l00029"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#a63336855381014fc7b63d7bdc6786385">00029</a>                 <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="classc_facets.html#a63336855381014fc7b63d7bdc6786385">set_BaseQuery</a>($str_BaseQuery)
<a name="l00030"></a>00030                 {
<a name="l00031"></a>00031                         $this-&gt;m_str_BaseQuery = $str_BaseQuery;
<a name="l00032"></a>00032                 }
<a name="l00033"></a>00033 
<a name="l00034"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#ae19588d3afaf61fbb3999b3fca69c0d1">00034</a>                 <span class="keyword">public</span> <span class="keyword">function</span> set_SolrType($int_SolrType)
<a name="l00035"></a>00035                 {
<a name="l00036"></a>00036                         $this-&gt;m_int_SolrType = $int_SolrType;
<a name="l00037"></a>00037 
<a name="l00038"></a>00038                         <span class="keywordflow">switch</span> ($this-&gt;m_int_SolrType)
<a name="l00039"></a>00039                         {
<a name="l00040"></a>00040                                 <span class="keywordflow">case</span> self::C_INT_SOLR_TYPE_REAPER:
<a name="l00041"></a>00041                                         require_once code\cConfig::C_STR_SOLR_PATH . <span class="stringliteral">&#39;/Classes/cReaper_Solr.php&#39;</span>;
<a name="l00042"></a>00042                                         $this-&gt;m_obj_Solr = new \cReaper_Solr();
<a name="l00043"></a>00043                                         <span class="keywordflow">break</span>;
<a name="l00044"></a>00044                                 <span class="keywordflow">case</span> self::C_INT_SOLR_TYPE_GROUNDEFFECT:
<a name="l00045"></a>00045                                         require_once code\cConfig::C_STR_SOLR_PATH . <span class="stringliteral">&#39;/Classes/cGE_Solr.php&#39;</span>;
<a name="l00046"></a>00046                                         $this-&gt;m_obj_Solr = new \cGE_Solr();
<a name="l00047"></a>00047                                         <span class="keywordflow">break</span>;
<a name="l00048"></a>00048                                 <span class="keywordflow">case</span> self::C_INT_SOLR_TYPE_WIKI:
<a name="l00049"></a>00049                                         require_once code\cConfig::C_STR_SOLR_PATH . <span class="stringliteral">&#39;/Classes/cWiki_Solr.php&#39;</span>;
<a name="l00050"></a>00050                                         $this-&gt;m_obj_Solr = new \cWiki_Solr();
<a name="l00051"></a>00051                                         <span class="keywordflow">break</span>;
<a name="l00052"></a>00052                                 <span class="keywordflow">default</span>:
<a name="l00053"></a>00053 
<a name="l00054"></a>00054                                         <span class="keywordflow">break</span>;
<a name="l00055"></a>00055                         }
<a name="l00056"></a>00056                 }
<a name="l00057"></a>00057 
<a name="l00058"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#a25d4e61dd66562c1d7a78e42c2e4768e">00058</a>                 <span class="keyword">public</span> <span class="keyword">function</span> <a class="code" href="classc_facets.html#a25d4e61dd66562c1d7a78e42c2e4768e">get_OutputArray</a>()
<a name="l00059"></a>00059                 {
<a name="l00060"></a>00060                         $arr_Output = array();
<a name="l00061"></a>00061                         <span class="keywordflow">if</span> (!$this-&gt;m_str_Facet)
<a name="l00062"></a>00062                         {
<a name="l00063"></a>00063                                 $arr_Output[<span class="stringliteral">&quot;success&quot;</span>] = <span class="keyword">false</span>;
<a name="l00064"></a>00064                                 $arr_Output[<span class="stringliteral">&quot;errors&quot;</span>] = array();
<a name="l00065"></a>00065                                 $arr_Output[<span class="stringliteral">&quot;errors&quot;</span>][<span class="stringliteral">&quot;msg&quot;</span>] = <span class="stringliteral">&quot;You have not specified a Facet to search for.&quot;</span>;
<a name="l00066"></a>00066                                 <span class="keywordflow">return</span> $arr_Output;
<a name="l00067"></a>00067                         }
<a name="l00068"></a>00068 
<a name="l00069"></a>00069                         $obj_Response = $this-&gt;m_obj_Solr-&gt;search(
<a name="l00070"></a>00070                                 $this-&gt;m_str_BaseQuery, 
<a name="l00071"></a>00071                                 0,
<a name="l00072"></a>00072                                 0,
<a name="l00073"></a>00073                                 array(
<a name="l00074"></a>00074                                 <span class="stringliteral">&quot;rows&quot;</span>                   =&gt; 0,
<a name="l00075"></a>00075                                 <span class="stringliteral">&quot;facet.field&quot;</span>    =&gt; $this-&gt;m_str_Facet,
<a name="l00076"></a>00076                                 <span class="stringliteral">&quot;facet.mincount&quot;</span> =&gt; 1,
<a name="l00077"></a>00077                                 <span class="stringliteral">&quot;facet.prefix&quot;</span>   =&gt; $this-&gt;m_str_Prefix,
<a name="l00078"></a>00078                                 <span class="stringliteral">&quot;facet&quot;</span>                  =&gt; <span class="stringliteral">&quot;on&quot;</span>
<a name="l00079"></a>00079                                 )
<a name="l00080"></a>00080                         );
<a name="l00081"></a>00081 
<a name="l00082"></a>00082                         <span class="keywordflow">if</span> ($obj_Response-&gt;getHttpStatus() == 200)
<a name="l00083"></a>00083                         {
<a name="l00084"></a>00084                                 $arr_Output[<span class="stringliteral">&quot;terms&quot;</span>] = array();
<a name="l00085"></a>00085                                 <span class="comment">//print_r($obj_Response);</span>
<a name="l00086"></a>00086                                 <span class="keywordflow">if</span>(isset($obj_Response-&gt;facet_counts))
<a name="l00087"></a>00087                                 {
<a name="l00088"></a>00088                                         <span class="keywordflow">foreach</span> ($obj_Response-&gt;facet_counts-&gt;facet_fields as $str_Field)
<a name="l00089"></a>00089                                         {
<a name="l00090"></a>00090                                                 <span class="keywordflow">foreach</span> ($str_Field as $str_Term =&gt; $int_Count)
<a name="l00091"></a>00091                                                 {
<a name="l00092"></a>00092                                                         $arr_Temp = array();
<a name="l00093"></a>00093                                                         <span class="keywordflow">if</span>(is_numeric($str_Term))
<a name="l00094"></a>00094                                                         {
<a name="l00095"></a>00095                                                                 $arr_Temp[<span class="stringliteral">&quot;term&quot;</span>] = (float)$str_Term;
<a name="l00096"></a>00096                                                         }
<a name="l00097"></a>00097                                                         <span class="keywordflow">else</span>
<a name="l00098"></a>00098                                                         {
<a name="l00099"></a>00099                                                                 $arr_Temp[<span class="stringliteral">&quot;term&quot;</span>] = $str_Term;
<a name="l00100"></a>00100                                                         }
<a name="l00101"></a>00101                                                         $arr_Temp[<span class="stringliteral">&quot;count&quot;</span>] = $int_Count;
<a name="l00102"></a>00102                                                         $arr_Temp[<span class="stringliteral">&quot;label&quot;</span>] = $str_Term . <span class="stringliteral">&quot; ($int_Count)&quot;</span>;
<a name="l00103"></a>00103                                                         $arr_Output[<span class="stringliteral">&quot;terms&quot;</span>][] = $arr_Temp;
<a name="l00104"></a>00104         
<a name="l00105"></a>00105                                                 }
<a name="l00106"></a>00106                                         }
<a name="l00107"></a>00107                                 }
<a name="l00108"></a>00108                         }
<a name="l00109"></a>00109                         <span class="keywordflow">else</span>
<a name="l00110"></a>00110                         {
<a name="l00111"></a>00111                                 $arr_Output[<span class="stringliteral">&quot;success&quot;</span>] = <span class="keyword">false</span>;
<a name="l00112"></a>00112                                 $arr_Output[<span class="stringliteral">&quot;errors&quot;</span>] = array();
<a name="l00113"></a>00113                                 $arr_Output[<span class="stringliteral">&quot;errors&quot;</span>][<span class="stringliteral">&quot;msg&quot;</span>] = $obj_Response-&gt;getHttpStatusMessage();
<a name="l00114"></a>00114                                 <span class="keywordflow">return</span> $arr_Output;
<a name="l00115"></a>00115                         }
<a name="l00116"></a>00116                         <span class="keywordflow">return</span> $arr_Output;
<a name="l00117"></a>00117                 }
<a name="l00118"></a>00118 
<a name="l00119"></a><a class="code" href="classampleharvest_1_1code_1_1search_1_1c_facets.html#af3c4198a1499b814702ae4b2a65bcf61">00119</a>                 <span class="keyword">public</span> <span class="keyword">function</span> get_OutputJSON()
<a name="l00120"></a>00120                 {
<a name="l00121"></a>00121                         <span class="keywordflow">return</span> json_encode($this-&gt;<a class="code" href="classc_facets.html#a25d4e61dd66562c1d7a78e42c2e4768e">get_OutputArray</a>());
<a name="l00122"></a>00122                 }
<a name="l00123"></a>00123         }
<a name="l00124"></a>00124 ?&gt;
</pre></div></div>
</div>
  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="c_facets_8php.html">cFacets.php</a>      </li>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Namespaces</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Variables</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>


    <li class="footer">Generated on Mon Jan 23 2012 13:34:19 for AmpleHarvest by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.5.1 </li>
   </ul>
 </div>


</body>
</html>
